package com.itcat.controller;

import com.itcat.common.CommonResult;
import com.itcat.mysql.pojo.PmsSkuStock;
import com.itcat.service.PmsSkuStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Jerry Broker
 * @project_name rainbow-mall
 * @create 2022-04-04 9:15
 */
@RestController
@RequestMapping("/sku")
public class PmsSkuStockController {

    @Autowired
    private PmsSkuStockService pmsSkuStockService;

    /**
     * 根据商品ID及sku编码模糊搜索sku库存
     * @param pid
     * @param keyword
     * @return
     */
    @GetMapping("/{pid}")
    public CommonResult getSkuByPid(@PathVariable Integer pid, String keyword){
        List<PmsSkuStock> list = pmsSkuStockService.getSkuByPid(pid, keyword);
        return CommonResult.success(list);
    }


    /**
     * 批量更新sku库存信息
     * @param skuStockList
     * @return
     */
    @PostMapping("/update/{pid}")
    public CommonResult updateSku(@PathVariable Integer pid , @RequestBody List<PmsSkuStock> skuStockList){
        pmsSkuStockService.updateSku(pid, skuStockList);
        return CommonResult.success();
    }

}
